package com.example.administrator.caigou51.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.alibaba.fastjson.JSON;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.bean.MainDataBean;
import com.example.administrator.caigou51.bean.NoGoodsBean;
import com.example.administrator.caigou51.global.App;
import com.example.administrator.caigou51.global.Constant;
import com.example.administrator.caigou51.recyclerCard.basic.MaterialListView;
import com.example.administrator.caigou51.recyclerCard.card.AddAgainGoodsCard;
import com.example.administrator.caigou51.request.BaseResponse;
import com.example.administrator.caigou51.request.ICallBackForRequestServer;
import com.example.administrator.caigou51.request.RequestServerManager;

import java.util.List;

/**
 * Created by Administrator on 2016/9/5/005.
 */
public class AddAgainGoodsActivity   extends GBaseActivity {
    MaterialListView material_listview;
    LinearLayout linearLayoutEmpty;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        super.setContentViewFor720_1280(R.layout.activity_add_again_goods);
        findViewByIds();
        initDatas();
        TaskGetMainData(false);
    }

    private void findViewByIds() {
        material_listview = (MaterialListView) findViewById(R.id.material_listview);
        linearLayoutEmpty= (LinearLayout) findViewById(R.id.linearLayoutEmpty);linearLayoutEmpty.setVisibility(View.GONE);
    }
    private void initDatas() {
        setTopTitle("补货申请记录");
    }
    private void fillArrayInListView(List<NoGoodsBean>  noGoodsBeanList) {
        material_listview.clear();
        for (int i=0;i<noGoodsBeanList.size();i++)
        {
            AddAgainGoodsCard addAgainGoodsCard=new AddAgainGoodsCard(this);
            addAgainGoodsCard.setNoGoodsBean(noGoodsBeanList.get(i));
            material_listview.add(addAgainGoodsCard);
        }


    }

    private void TaskGetMainData(final boolean isloadmore) {
        RequestServerManager.getInstanceDIY().handleMethodDIY((GBaseActivity) getActivity(), material_listview, isloadmore, null,
                Constant.getRootUrl() + Constant.Action.Action_NoGoodsList, Constant.Action.Action_NoGoodsList, RequestServerManager.getInstanceDIY().
                        getRequestParams(Constant.Action.Action_NoGoodsList, App.getUserBean().getUserid(),App.getUserBean().getSession_id()), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                        // JSONObject jsonObject = (JSONObject) result.getData();
                        List<NoGoodsBean>  noGoodsBeanList= JSON.parseArray(result.getData().toString(), NoGoodsBean.class);
                        fillArrayInListView(noGoodsBeanList);
                        Log.e("userBean", result.getData().toString());
                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {

                    }
                });
    }
}